package com.thinkinjava;

/**
 * @Description instanceof 与Class的等价性
 * @Author
 * @Date 2019/9/30 19:45
 **/
public class FamilyVsExactType {

    static void test(Object x){
        System.out.println("Test x of type "+x.getClass());
        System.out.println("x instanceof base "+(x instanceof Base));
        System.out.println("x insyanceof dervied "+(x instanceof Dervied));
        System.out.println("Bace.isInstance(x) "+Base.class.isInstance(x));
        System.out.println("Dervied.isInstance(x) "+Dervied.class.isInstance(x));
        System.out.println("x.getClass() == Base.class " + (x.getClass()== Base.class));
        System.out.println("x.getClass() == Dervide.class "+(x.getClass()== Dervied.class));
        System.out.println("x.getClass().equals(Base.class) "+(x.getClass().equals(Base.class)));
        System.out.println("x.getClass().equals(Dervied.class) "+(x.getClass().equals(Dervied.class)));
    }

    public static void main(String[] args) {
        System.out.println(args);
        test(new Base());
        System.out.println("______");
        test(new Dervied());
    }
}

class Base{}
class Dervied extends Base{}
